package client;

import javax.swing.JOptionPane;
import java.io.File;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;


public class alarmbox {
	
	// Opens an Warningmessage box when an alarm occurs.
	public static void playAlarm(String message, String sensor) {
		try {
			//Put an audiofile into an inputstream.
			AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("C:\\alarmsound.wav").getAbsoluteFile());
	        Clip clip = AudioSystem.getClip();
	        clip.open(audioInputStream);
	        // Start audiostream and loop for a long time.
			clip.start();
//	        clip.loop(2);
		}
		// Writes message when any errors occur.
		catch(Exception ex) {
			System.out.println("Error with playing sound.");
	        ex.printStackTrace();
		}
		// Make the OptionPane panel that shows the warningmessage.
		JOptionPane.showMessageDialog(null,message,sensor,JOptionPane.WARNING_MESSAGE);
	}
}

